<?php

class Core_Agent_Component_Subject_View_Subject_Index extends Core_Agent_Share_View_Grid {

//    protected function buildToolbar($toolbar) {
//        parent::buildToolbar($toolbar);
//        if ($this->getIdentity()->isAllowAction('article_review')) {
//            $group = $toolbar->createGroup('status');
//            $group->addButton($this->__('share.button.publish'))
//                    ->bindEvent('click', "submitGridChecked('" . $this->getGrid()->getId() . "', '" . $this->getUrl(array('status'=>'published'), 'review') . "')");
//            $group->addButton($this->__('share.button.forbid'))
//                    ->bindEvent('click', "forbidGridChecked('" . $this->getGrid()->getId() . "', '" . $this->getUrl(array('status'=>'forbidden'), 'review') . "')");
//        }
//        if ($this->getIdentity()->isAllowAction('article_delete')) {
//            $group = $toolbar->createGroup('delete');
//            $group->addButton($this->__('share.button.delete'))
//                    ->bindEvent('click', "submitGridChecked('" . $this->getGrid()->getId() . "', '" . $this->getUrl(NULL, 'delete') . "')");
//        }
//    }

    protected function buildGrid($grid) {
        $filter = new Kd_Object($this->getRequest()->getParameter('filter'));
        $grid->setId('content_grid')
                ->setPrimaryKey('id')
                ->setAllowFilter(TRUE)
                ->setSortField($this->getRequest()->getParameter('sort', 'id'))
                ->setSortDirection($this->getRequest()->getParameter('dir', 'asc'))
                ->setSortUrlFormat($this->getSortUrl());
        $grid->addLabelColumn($this->__('share.label.title'), 'title', '{name}')
                ->setTextboxFilter(NULL, NULL, $filter->getData('title'))
                ->setSortField('title')
                ->setWidth(100);
        $grid->addLabelColumn($this->__('subject.label.category'), 'categoryname', '{category_name}')
                ->setTextboxFilter(NULL, NULL, $filter->getData('categoryname'))
                ->setSortField('category_id')
                ->setAlign('center')
                ->setWidth(50);
        $grid->addLabelColumn($this->__('article.label.click_count'), 'clickcount', '{click_count}')
                ->setSortField('clickcount')
                ->setAlign('center')
                ->setWidth(40);
        $grid->addLabelColumn($this->__('share.label.status'), 'status', '{{lang "status.publication.{status}"}}')
                ->setSelectFilter(NULL, NULL, Kd_Localize_Helper::getLanguageItems('status.publication'), NULL, NULL, $filter->getData('status'))
                ->setSortField('status')
                ->setAlign('center')
                ->setWidth(50);
        $grid->addLinkColumn('#', 'edit', $this->getUrl(array('id' => '{id}'), 'edit'), $this->__('share.button.edit'))
                ->setWidth(40)
                ->setAlign('center');
        $grid->addLinkColumn('#', 'edit_article', $this->getUrl(array('subject_id' => '{id}'), 'index','article'), $this->__('subject.label.article_edit'))
                ->setWidth(40)
                ->setAlign('center');
        $grid->addLinkColumn('#', 'edit_concessions', $this->getUrl(array('subject_id' => '{id}'), 'index','concessions'), $this->__('subject.label.concessions_edit'))
                ->setWidth(40)
                ->setAlign('center');
        $grid->addLinkColumn('#', 'preview', $this->getUrl(array('id' => '{id}'), 'preview'), $this->__('share.button.preview'), '_blank')
                ->setWidth(40)
                ->setAlign('center');
        $grid->setDataSource($this->getSubjects()->toArray());
        parent::buildGrid($grid);
    }

    protected function buildPagination($pagination) {
        $url = $this->getPaginationUrl();
        $pagination->setUrlFormat($url)->setRecordCount($this->getRecords());
        parent::buildPagination($pagination);
    }

}